**********************************************************
**********************************************************
* This program creates a sample by year and for all years
**********************************************************
**********************************************************

*Brochu
* minimum wage project
* LFS

* program name: merging_panels.do
* created: June 9, 2014
* updated: June 9, 2014

clear


/* set directories */
* note:  no spaces allowed in directory names.

* rawdata is the directory that contains the raw data
local rawdata1 "V:\Townsend_5609\Split_sample_whyleft\Data"
local rawdata2 "V:\Townsend_5609\Iain_Feb27\Data"

* workdata is the directory that contains the working data sets
local workdata2 "V:\Townsend_5609\Iain_Feb27\WorkingData"


set more off

set memory 500m
set matsize 600


******************************************************
******************************************************
* creating a sample by year and for all years
******************************************************
******************************************************

forvalues year1=1996/2015 { 

	clear
	// Append the monthly datasets
	append using	///
		`workdata2'\panel_6M_1_`year1'.dta 	///
		`workdata2'\panel_6M_2_`year1'.dta 	///
		`workdata2'\panel_6M_3_`year1'.dta 	///
		`workdata2'\panel_6M_4_`year1'.dta 	///
		`workdata2'\panel_6M_5_`year1'.dta 	///
		`workdata2'\panel_6M_6_`year1'.dta 	///
		`workdata2'\panel_6M_7_`year1'.dta 	///
		`workdata2'\panel_6M_8_`year1'.dta 	///
		`workdata2'\panel_6M_9_`year1'.dta 	///
		`workdata2'\panel_6M_10_`year1'.dta 	///
		`workdata2'\panel_6M_11_`year1'.dta 	///
		`workdata2'\panel_6M_12_`year1'.dta
		
	// Generate year and month variables
	gen year  = `year1'
	gen month = smth1
	
	// Save the new dataset
	save `workdata2'\panel_6M_`year1'.dta, replace  
}


forvalues year1=2016/2016 { 

	clear
	// Append the monthly datasets
	append using	///
		`workdata2'\panel_6M_1_`year1'.dta 	///
		`workdata2'\panel_6M_2_`year1'.dta 	///
		`workdata2'\panel_6M_3_`year1'.dta 	///
		`workdata2'\panel_6M_4_`year1'.dta 	///
		`workdata2'\panel_6M_5_`year1'.dta 	///
		`workdata2'\panel_6M_6_`year1'.dta 	///
		`workdata2'\panel_6M_7_`year1'.dta 	///
		`workdata2'\panel_6M_8_`year1'.dta 	///
		`workdata2'\panel_6M_9_`year1'.dta 	
		
	// Generate year and month variables
	gen year  = `year1'
	gen month = smth1
	
	// Save the new dataset
	save `workdata2'\panel_6M_`year1'.dta, replace  
}



// Put together all the annual datasets
clear
append using	///
	`workdata2'\panel_6M_1996.dta	///
	`workdata2'\panel_6M_1997.dta	///
	`workdata2'\panel_6M_1998.dta	///
	`workdata2'\panel_6M_1999.dta	///
	`workdata2'\panel_6M_2000.dta	///
	`workdata2'\panel_6M_2001.dta	///
	`workdata2'\panel_6M_2002.dta	///
	`workdata2'\panel_6M_2003.dta	///
	`workdata2'\panel_6M_2004.dta	///
	`workdata2'\panel_6M_2005.dta	///
	`workdata2'\panel_6M_2006.dta	///
	`workdata2'\panel_6M_2007.dta	///
	`workdata2'\panel_6M_2008.dta	///
	`workdata2'\panel_6M_2009.dta	///
	`workdata2'\panel_6M_2010.dta	///
	`workdata2'\panel_6M_2011.dta	///
	`workdata2'\panel_6M_2012.dta	///
	`workdata2'\panel_6M_2013.dta	///
	`workdata2'\panel_6M_2014.dta	///
	`workdata2'\panel_6M_2015.dta	///
	`workdata2'\panel_6M_2016.dta	

// Save the dataset with all years
save `workdata2'\panel_6M_allyears.dta, replace


